package studentmanagement;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Scanner;

public class StudentManagement {
    public static void main(String[] args) {
        System.out.println("==========初始化学员信息=======");
        List<Student> students = new ArrayList<>();
        students.add(new Student(1001, "范国荣", "男"));
        students.add(new Student(1002, "范景明", "男"));
        students.add(new Student(1003, "何玉聪", "女"));
        System.out.println(students);
        System.out.println("1、添加学员信息\n" + "2、删除学员信息\n" + "3、根据学号查看学员信息\n" + "4、查看所有学员信息\n" + "5、退出系统");
        System.out.println("请输入您的选择的：");
        Scanner scanner = new Scanner(System.in);
        int selectId = scanner.nextInt();
        switch (selectId) {
            case 1:
                addStudent(students);
                break;
            case 2:
                deleteStudernt(students);
                break;
            case 3:
                getstudentByid(students);
                break;
            case 4:
                getallStudent(students);
                break;
            case 5:
                System.out.println("不玩了，退出系统！");
                System.exit(0);
        }
    }

    //添加学员信息
    public static void addStudent(List<Student> students) {
        System.out.println("=====添加学员方法=====");
        int num;
        int i;
        System.out.println("请输入需要添加的学员个数：");
        Scanner scanner = new Scanner(System.in);
        num = scanner.nextInt();
        for (i = 0; i < num; i++) {
            System.out.println("请输入第" + (i + 1) + "个学员信息");
            System.out.println("请输入学号：");
            int id = scanner.nextInt();
            System.out.println("请输入姓名：");
            String name = scanner.next();
            System.out.println("请输入性别：");
            String sex = scanner.next();
            Student student = new Student(id, name, sex);
            students.add(student);
            System.out.println("添加的学员信息是：" + student);
        }
        System.out.println("添加后的学员信息是：" + students);
    }

    //删除学员信息
    public static void deleteStudernt(List<Student> students) {
        System.out.println("=====删除学员方法=====");
        System.out.println("请输入需要删除的学生学号：");
        Scanner scanner = new Scanner(System.in);
        int deleteId = scanner.nextInt();
        for (Student student : students) {
            if (Objects.equals(deleteId, student.getId())) {
                System.out.println("删除的学员信息是：" + student);
                students.remove(student);
                System.out.println("删除后的学员信息是：" + students);
            }
        }

    }

    //按照学号查看学员信息
    public static void getstudentByid(List<Student> students) {
        System.out.println("=====按照学号学员方法=====");
        System.out.println("请输入需要查看的学生学号：");
        Scanner scanner = new Scanner(System.in);
        int getId = scanner.nextInt();
        for (Student student : students) {
            if (Objects.equals(getId, student.getId())) {
                System.out.println("按照学号查看的学员信息是：" + student);
            }
        }
    }

    //查询所有学员信息
    public static void getallStudent(List<Student> students) {
        System.out.println("=====查询所有学员方法=====");
        System.out.println("所有学员信息：" + students);
    }

}

